package dxn.nl.file.client.model.dto;

import dxn.nl.file.client.model.enums.ExportDealResultTypeEnum;
import lombok.Data;

import java.util.UUID;

@Data
public class TransferMessageDto {
    private int type;
    private TransferMessageConfig config;
    private TransferMessageData messageData;
    private byte[] data;

    public TransferMessageDto()
    {
        this.config = new TransferMessageConfig();
        this.messageData = new TransferMessageData();
    }

    public TransferMessageDto(int type,int exportType,String appId,String modeCode
            ,String orgCode,String orgName,String userCode,String userName)
    {
        this.type = type;
        this.config = new TransferMessageConfig();
        this.messageData = new TransferMessageData();

        this.config.setId(UUID.randomUUID().toString());
        this.config.setFileType(exportType);
        this.config.setAppId(appId);
        this.config.setModeCode(modeCode);
        this.config.setDealResult(ExportDealResultTypeEnum.continue_deal.code);
        this.config.setErrorMessage(null);

        this.messageData.setAreaCode(orgCode);
        this.messageData.setOrgCode(orgCode);
        this.messageData.setOrgName(orgName);
        this.messageData.setUserCode(userCode);
        this.messageData.setUserName(userName);
    }

    public TransferMessageDto convertNewResultMessage()
    {
        return convertNewResultMessage(this.type,ExportDealResultTypeEnum.continue_deal.code);
    }

    public TransferMessageDto convertNewResultMessage(int dealType,int resultType)
    {
        return convertNewResultMessage(dealType,resultType,null);
    }

    public TransferMessageDto convertNewResultMessage(int dealType,int resultType,String error)
    {
        TransferMessageDto dto = new TransferMessageDto();
        dto.setType(dealType);
        dto.setConfig(new TransferMessageConfig());
        dto.setMessageData(new TransferMessageData());

        dto.getConfig().setId(this.config.getId());
        dto.getConfig().setSessionId(this.config.getSessionId());
        dto.getConfig().setServer(this.config.getServer());
        dto.getConfig().setClient(this.config.getClient());
        dto.getConfig().setAppId(this.config.getAppId());
        dto.getConfig().setModeCode(this.config.getModeCode());
        dto.getConfig().setFileType(this.config.getFileType());
        dto.getConfig().setDealResult(resultType);
        dto.getConfig().setErrorMessage(error);

        dto.getMessageData().setAreaCode(this.messageData.getAreaCode());
        dto.getMessageData().setOrgCode(this.messageData.getOrgCode());
        dto.getMessageData().setOrgName(this.messageData.getOrgName());
        dto.getMessageData().setUserName(this.messageData.getUserName());
        dto.getMessageData().setUserCode(this.messageData.getUserCode());
        dto.getMessageData().setCurrentParam(this.messageData.getCurrentParam());
        dto.getMessageData().setSheetName(this.messageData.getSheetName());

        return dto;
    }
}
